define("view/Login", [
  "component/LoginForm",
  "restTemplate",
  "text!./login.html",
  "css!./login.css"
], function( LoginForm, restTemplate, template) {
  // console.log(template)
    return {
        template: template,
        components: {
            LoginForm
        },
        methods: {
            handleSubmit({ userName, password }) {
                restTemplate.request(
                    {
                        url:'/login',
                        method: 'post',
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        },
                        params:{
                            username: userName,
                            password: password,
                            redirect_uri: wxContext.getViewData().redirectUri
                        }
                    }
                ).then((res)=>{
                    if(res.code && res.code==200){
                        location.href=res.data;
                    }else if(res.code && res.code !=200){
                        this.$Message.error(res.error)
                    }else {
                        this.$Message.error('登录失败')
                    }
                },(reason )=>{
                    console.log(reason);
                    this.$Message.error(reason)
                })
            }
        },
        created(){
            document.title=wxContext.getViewData().name;
        }
    };

});
